package com.terrynoya.fight.stateMachine.controllers
{
	import com.terrynoya.fight.char.Character;
	import com.terrynoya.fight.stateMachine.StateController;
	import com.terrynoya.fight.util.Misc;
	import com.terrynoya.geom.MVector2D;
	
	public class TargetBind extends StateController
	{
		private var _time:int;
		private var _targetId:int;
		private var _pos:MVector2D;
		
		public function TargetBind(name:String)
		{
			super(name);
		}
		
		override public function build():void
		{
			this._time = this.getAttributeAsInt("time",1);
			this._pos = Misc.getVelocity(this.getAttribute("pos"));
			this._targetId = this.getAttributeAsInt("id",int.MIN_VALUE);
		}
		
		override public function run(character:Character):void
		{
			var targetList:Array = character.getTargets(this._targetId);
			for (var i:int = 0; i < targetList.length; i++) 
			{
				var target:Character = targetList[i];
				target.bind.set(character,this._pos,this._time,0,true);
				trace("TargetBind pos:",this._pos);
			}
		}
	}
}